﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DepartmentManagement.Entity
{
    /// <summary>
    /// 系统登录账号
    /// </summary>
    public class Account
    {
        private string _userName;

        public string UserName
        {
            get { return _userName; }
        }

        private string _md5Password;

        private bool _logged;

        public bool Logged
        {
            get { return _logged; }
        }


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public Account()
        {
            _userName = string.Empty;
            _md5Password = string.Empty;
            _logged = false;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userName">用户名</param>
        public Account(string userName)
        {
            _userName = userName;
            _md5Password = string.Empty;
            _logged = false;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="originalPassword">明文密码</param>
        public Account(string userName, string originalPassword)
        {
            _userName = userName;
            _md5Password = string.Empty;
            _logged = false;

            if (null != originalPassword && string.Empty != originalPassword)
            {
                _md5Password = MiscFunction.ComputeMD5(originalPassword);
            }
        }
        #endregion

        #region 静态方法
        /// <summary>
        /// 获取数据库中所有存在的用户账号
        /// </summary>
        /// <returns>用户账号列表</returns>
        public static List<string> GetAllAccounts()
        {
            List<string> result = new List<string>();

            //TODO: 这里添加从数据库MISC_Users表中选出的用户账户

            return result;
        }

        /// <summary>
        /// 根据用户名、密码建立账号
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="originalPassword">明文密码</param>
        /// <returns>执行结果</returns>
        public static bool Create(string userName, string originalPassword)
        {
            bool result = false;

            //TODO: 这里添加账号建立代码

            return result;
        }
        #endregion

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns>登录结果</returns>
        public bool Login()
        {
            bool result = false;

            //TODO: 这里添加验证账号是否能够登录的代码

            _logged = result;

            return result;
        }

        /// <summary>
        /// 修改用户账号
        /// </summary>
        /// <param name="newPassword">新明文密码</param>
        /// <returns>修改结果</returns>
        public bool ModifyPassword(string newPassword)
        {
            bool result = false;

            if (!_logged)
                Login();

            if (_logged)
            {
                // 成功登录
                if (null != newPassword && string.Empty != newPassword)
                {
                    //TODO: 这里增加密码修改代码 
                }
            }

            return result;
        }
    }
}
